@page "/client/exam/{id:long}"
@model CodeSpirit.Web.Pages.Client.ExamModel
@{
    ViewData["Title"] = "在线考试系统";
    var examId = ViewContext.RouteData.Values["id"]?.ToString();
    var isDevelopment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development";
}

@section Head
{
    <meta name="description" content="在线考试系统 - 高效、安全的考试平台">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    
    <!-- 禁用缓存，确保考试内容及时更新 -->
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    
    <!-- 考试系统专用样式 -->
    <resource path="css/client/exam.css" type="css" />
    
    <!-- 考试页面特定初始化数据 -->
    <script>
        // 全局配置对象
        window.CS_CONFIG = {
            examId: "@examId",
            environment: "@Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")",
            isDevelopment: @Json.Serialize(isDevelopment),
            security: {
                blockCopy: true,
                blockPaste: true,
                blockRightClick: true,
                blockPrint: true
            },
            amisOptions: {
                theme: 'antd',
                locale: 'zh-CN'
            }
        };
    </script>
}

<div id="root" class="app-wrapper"></div>

@section Scripts {
    <!-- 安全和监控模块 -->
    <resource path="js/client/screenSwitchDetector.js" type="js" />
    
    <!-- 防作弊代码 - 按环境加载 -->
    <script>
    (function() {
        'use strict';
        
        const config = window.CS_CONFIG || {};
        
        // 仅在非开发环境中应用完整的安全措施
        if (!config.isDevelopment) {
            // 检测开发者工具
            const detectDevTools = () => {
                const threshold = 160;
                const widthDiff = window.outerWidth - window.innerWidth > threshold;
                const heightDiff = window.outerHeight - window.innerHeight > threshold;
                
                if (widthDiff || heightDiff) {
                    console.warn('可能检测到开发工具已打开');
                }
            };
            
            // 定期检测
            setInterval(detectDevTools, 1000);
            
            // 禁用开发者工具快捷键
            document.addEventListener('keydown', e => {
                if (e.keyCode === 123 || (e.ctrlKey && e.shiftKey && e.keyCode === 73)) {
                    e.preventDefault();
                    return false;
                }
            });
        }
        
        // 以下安全措施在所有环境中应用
        if (config.security) {
            // 禁用右键
            if (config.security.blockRightClick) {
                document.addEventListener('contextmenu', e => e.preventDefault());
            }
            
            // 禁用复制粘贴
            if (config.security.blockCopy || config.security.blockPaste) {
                ['copy', 'cut', 'paste'].forEach(evt => {
                    document.addEventListener(evt, e => {
                        const type = evt === 'paste' ? 'blockPaste' : 'blockCopy';
                        if (config.security[type]) e.preventDefault();
                    });
                });
            }
            
            // 禁用打印
            if (config.security.blockPrint) {
                window.addEventListener('beforeprint', e => e.preventDefault());
            }
        }
        
        // 防止iframe嵌套
        if (window.self !== window.top) {
            window.top.location = window.self.location;
        }
    })();
    </script>
    
    <!-- 考试主模块 -->
    <resource path="js/client/exam.js" type="js" />
} 